package com.matrix.common.domain;

import com.matrix.common.enums.ErrorCode;
import lombok.Data;

import java.io.Serializable;

/**
 * @author 有点甜
 * @since 2025/7/25
 * @param <T>
 */
@Data
public class Result<T> implements Serializable {

    private Integer code;
    private String message;
    private T data;

    public static <T> Result<T> success() {
        Result<T> result = new Result<>();
        result.code = ErrorCode.SUCCESS.getCode();
        result.message = ErrorCode.SUCCESS.getMessage();
        return result;
    }

    public static <T> Result<T> success(T object) {
        Result<T> result = new Result<>();
        result.data = object;
        result.code = ErrorCode.SUCCESS.getCode();
        result.message = ErrorCode.SUCCESS.getMessage();
        return result;
    }

    public static <T> Result<T> error(ErrorCode errorCode) {
        Result<T> result = new Result<>();
        result.message = errorCode.getMessage();
        result.code = errorCode.getCode();
        return result;
    }

    public static <T> Result<T> error(String message) {
        Result<T> result = new Result<>();
        result.message = message;
        result.code = ErrorCode.SYSTEM_ERROR.getCode();
        return result;
    }
}
